package com.phaeton.beemeup.updatehandlers;

import java.util.ArrayList;
import java.util.Map;
import java.util.UUID;

import org.andengine.engine.handler.IUpdateHandler;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;

import android.util.Log;

import com.phaeton.beemeup.GameManager;
import com.phaeton.beemeup.entity.Bee;
import com.phaeton.beemeup.entity.BeeComb;
import com.phaeton.beemeup.entity.Comb;
import com.phaeton.beemeup.entity.Flower;
import com.phaeton.beemeup.entity.IComb;
import com.phaeton.beemeup.entity.IInsect;
import com.phaeton.beemeup.entity.Insect;
import com.phaeton.beemeup.entity.Wasp;
import com.phaeton.beemeup.entity.WaspComb;

public class InsectHandler extends IHandler {

	public InsectHandler(GameManager gameManager) {
		super(gameManager);
	}

	@Override
	public void init() {
		/*mGameManager.getLevel().registerUpdateHandler(new IUpdateHandler() {
			public void onUpdate(float pSecondsElapsed) {
				for(Bee bee: mGameManager.getBees().values()){	
					if((bee.getState() & IInsect.FLY) != 0){
						if(bee.getTarget() instanceof Flower && (((Flower)bee.getTarget()).getState() & Flower.OCCUPIED) != 0){
							bee.stop();
						}
						if(bee.getTarget() instanceof Comb && (((Comb)bee.getTarget()).getState() & IComb.OCCUPIED) != 0){
							bee.stop();
						}
					}
				}
				for(Wasp wasp: mGameManager.getWasps().values()){	
					if((wasp.getState() & IInsect.FLY) != 0){
						if(wasp.getTarget() instanceof Flower && (((Flower)wasp.getTarget()).getState() & Flower.OCCUPIED) != 0){
							wasp.stop();
						}
						if(wasp.getTarget() instanceof Comb && (((Comb)wasp.getTarget()).getState() & IComb.OCCUPIED) != 0){
							wasp.stop();
						}
					}
				}
			}

			public void reset() {
			}
          });
		
		//Fight
		mGameManager.getLevel().registerUpdateHandler(new IUpdateHandler() {
			public void onUpdate(float pSecondsElapsed) {

				for(final Bee bee: mGameManager.getBees().values()){	
					for(final Wasp wasp: mGameManager.getWasps().values()){
						
							if(wasp.getX() == bee.getX() && wasp.getY() == bee.getY()) {
								Fight thisFight = null;
								if(fights.size() > 0) {
									for(Fight fight: fights) {
										if(fight.getFightingBees().contains(bee)) {
											thisFight = fight;
										}
									}
								}
								
								if(thisFight == null) {
									thisFight = new Fight(bee.getX(), bee.getY(), mGameManager.getActivity().getSceneManager().getTiledTexture("BeeComb"), 
											mGameManager.getActivity().getVertexBufferObjectManager(), mGameManager);
									fights.add(thisFight);
								}
								
								if((bee.getState() & IInsect.FIGHT) == 0){
									thisFight.addBee(bee);
								}
								if((wasp.getState() & IInsect.FIGHT) == 0){
									thisFight.addWasp(wasp);
								}
								
							}
						}
					}
				}

			public void reset() {
			}
          });*/
	}

}
